package dviz.visualSystem.impl;

import java.util.HashSet;

public class AnimationClassLocator {
	static final String helperVO = "dviz.tools.helperVO";
	HashSet<String> prefixs;

	public AnimationClassLocator() {
		prefixs = new HashSet<String>();
		prefixs.add("");
		addPrefix(helperVO);
	}

	public void addPrefix(String prefix) {
		String s[] = prefix.split("\\.");
		String curPrefix = "";
		for (String str : s) {
			curPrefix += str + ".";
			prefixs.add(curPrefix);
		}
	}

	public Class findClass(String name) {
		Class clazz = null;
		for (String prefix : prefixs) {
			Class clz = null;
			try {
				clz = Class.forName(prefix + name);
				clz.asSubclass(AnimationObject.class);
			} catch (Exception e) {
				continue;
			}
			if (clazz != null && clz != null)
				throw new RuntimeException(
						"Duplicate definition of class found for:"
								+ clazz.getName() + " <-> " + prefix + name);
			if (clazz == null)
				clazz = clz;
		}
		if (clazz == null)
			throw new RuntimeException("Definition not found for class:" + name);
		return clazz;
	}
}
